import request from '@/utils/request'
import storage from '@/utils/storage'

export const getChannel = () => {
  return request({
    url: '/v1_0/user/channels'
  })
}
/**
 * 获取所有频道
 * @returns Promise
 */
export const getAllChannels = () => {
  return request({ url: '/v1_0/channels' })
}

export const delChannels = (target) => {
  return request({
    url: `/v1_0/user/channels/${target}`,
    method: 'DELETE'
  })
}

export const addChannelAPI = (id, seq) =>
  request({
    url: '/v1_0/user/channels',
    method: 'PATCH',
    data: {
      channels: [{ id, seq }]
    }
  })

// 封装未登录状态的方法
const HEIMA_TOUTIAO_MY_CHANNEL = 'HEIMA_TOUTIAO_MY_CHANNEL'
// 存储数据
export const setMyChannelsToLocal = (myChannels) => {
  storage.set(HEIMA_TOUTIAO_MY_CHANNEL, myChannels)
}
// 读取数据
export const getMyChannelsByLocal = () => {
  return storage.get(HEIMA_TOUTIAO_MY_CHANNEL)
}
